home *** CD-ROM | disk | FTP | other *** search
- /* trivial demo of Pictoid WDEF, Nigel Perry 90, 91, 92 */
- /* Comments? This program is trivial… */
-
- #include "Pictoid.h"
-
- #ifndef NIL
- #define NIL ((void *)0)
- #endif
- #define FRONTWIN ((WindowPtr)-1)
-
- #define BIG_DLOG 128
- #define BIG_DISMISS 1
-
- /* used to check for NewCWindow */
-
- #include <Traps.h>
-
- #pragma parameter __A0 GetOSTrapAddr(__D0)
- static pascal long GetOSTrapAddr(int trap) = 0xA346;
-
- #pragma parameter __A0 GetToolTrapAddr(__D0)
- static pascal long GetToolTrapAddr(int trap) = 0xA746;
-
- static Boolean TrapAvailable(int trap)
- { register long unimp = GetToolTrapAddr(_Unimplemented);
- register long addr;
-
- if(trap & 0x0800) /* toolbox */
- { trap &= 0x7FF;
- if( (trap >= 0x0400)
- || (((addr = GetToolTrapAddr(_InitGraf))
- == GetToolTrapAddr(_InitGraf | 0x0200))
- && (trap >= 0x0200)
- )
- ) trap = _Unimplemented;
- addr = GetToolTrapAddr(trap);
- }
- else
- addr = GetOSTrapAddr(trap);
- return addr != unimp;
- }
-
- /* used to check if window was framed */
- static framed(w, wl, base)
- WindowPtr w, *wl;
- int base;
- { int i;
-
- i = 8;
- while(i--)
- { if(w == *wl++)
- return(base & PW_AddFrame);
- base++;
- }
-
- return(0);
- }
-
- /* used to check if window is a "picture" window */
- static picwin(w, wl, base)
- WindowPtr w, *wl;
- int base;
- { int i;
-
- i = 8;
- while(i--)
- { if(w == *wl++)
- return(base >= 12);
- base++;
- }
-
- return(0);
- }
-
- eventLoop(WindowPtr *w, int base)
- { int stop;
- Rect r1;
- WindowPtr wind;
- EventRecord event;
- Rect size;
-
- stop = 0;
- size.left = 4; size.right = 32767;
- size.top = 4; size.bottom = 32767;
- r1.top = 0; r1.left = 0; r1.bottom = 32767; r1.right = 32767;
-
- while(!stop)
- { if( GetNextEvent(everyEvent, &event) )
- switch( event.what )
- { case updateEvt:
- BeginUpdate((WindowPtr)event.message);
- EndUpdate((WindowPtr)event.message);
- break;
- case keyDown:
- stop = 1;
- break;
- case mouseDown:
- switch( FindWindow(event.where, &wind) )
- { case inContent:
- if( picwin(wind, w, base) )
- { if( wind != FrontWindow() )
- SelectWindow(wind);
- else
- { SetPort(wind);
- FillRect(&r1, gray);
- while( StillDown() );
- EraseRect(&r1);
- }
- }
- else if( framed(wind, w, base) )
- { if( wind != FrontWindow() )
- SelectWindow(wind);
- else
- DragWindow(wind, event.where, &screenBits.bounds);
- }
- /* fall thru */
- case inDrag:
- if( event.modifiers & 0x0800 ) /* option key */
- { /* in asm as GrowWindow returns a long and
- SizeWindow wants two ints… */
- asm
- { subq.l #4,a7
- move.l wind,-(a7)
- move.l event.where,-(a7)
- pea size
- GrowWindow
- move.l (a7)+,d0
- beq.s @nogrow
- move.l wind,-(a7)
- move.l d0,-(a7)
- move.w #0,-(a7)
- SizeWindow
- ; CopyRgn(strucRgn, updateRgn) -> invalidate
- ; whole window area
- move.l wind,a0
- move.l OFFSET(WindowRecord,strucRgn)(a0),-(a7)
- move.l OFFSET(WindowRecord,updateRgn)(a0),-(a7)
- CopyRgn
- nogrow:
- }
- }
- else
- DragWindow(wind, event.where, &screenBits.bounds);
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- }
- }
-
- setupWindows(int variant, WindowPtr *wl, PicHandle p1, PicHandle p2,
- PicHandle p3, PicHandle p4, WDEFGlobals *gp)
- { EventRecord event;
- Rect r1, r2;
- int h, v;
- Boolean isColour = TrapAvailable(_GetNewCWindow);
-
- r1.top = 16; r1.left = 16; r1.bottom = 106; r1.right = 86;
-
- gp->pic = p1;
- gp->frame = p2;
- gp->flags.clonePic = gp->flags.cloneFrame = false;
- gp->flags.sharePic = gp->flags.shareFrame = true;
-
- /* do eight variations starting from variant */
- for(v = 0; v <= 240; v += 80)
- for(h = 0; h <= 256; h += 256)
- { r2 = r1;
- OffsetRect(&r2, h, v);
- if(variant == 12) { gp->pic = p3; gp->frame = p4; }
- if(isColour)
- *wl++ = (WindowPtr)NewCWindow(NIL, &r2, "\p", true, PictWDEF | variant, FRONTWIN, false, 0);
- else
- *wl++ = (WindowPtr)NewWindow(NIL, &r2, "\p", true, PictWDEF | variant, FRONTWIN, false, 0);
- /* NewWindow() will not draw the window's picture,
- calling CheckUpdate() will fix this - all subsequent
- redraws will be handled automatically by QD
- */
- CheckUpdate(&event);
- variant++;
- }
- }
-
- main()
- { int j, stop;
- WindowPtr w[16], wind;
- PicHandle p1, p2, p3, p4;
- EventRecord event;
- WDEFGlobals *gp;
- Rect size;
-
- InitGraf(&thePort);
- InitFonts();
- FlushEvents(everyEvent,0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NIL);
- InitCursor();
-
- if(!doDialog()) return;
-
- if(GetWDEFGlobals(true, &gp)) return;
-
- /* some pictures to draw */
- p1 = (PicHandle)GetResource('PICT', 103);
- p2 = (PicHandle)GetResource('PICT', 104);
- p3 = (PicHandle)GetResource('PICT', 101);
- p4 = (PicHandle)GetResource('PICT', 102);
-
- /* do first eight variations */
- setupWindows(0, w, p1, p2, p3, p4, gp);
-
- /* play with them */
- eventLoop(w, 0);
-
- /* clean up */
- for(j = 0; j < 8; j++) DisposeWindow(w[j]);
-
- /* now next eight */
- setupWindows(8, w, p1, p2, p3, p4, gp);
-
- /* play with them */
- eventLoop(w, 8);
-
- /* clean up */
- for(j = 0; j < 8; j++) DisposeWindow(w[j]);
-
- ReleaseResource(p1);
- ReleaseResource(p2);
- ReleaseResource(p3);
- ReleaseResource(p4);
-
- }
-